//
//  ShopCollectionViewCell.m
//  GouWoAi
//
//  Created by 赵佟越 on 16/5/6.
//  Copyright © 2016年 zhaotongyue. All rights reserved.
//

#import "ShopCollectionViewCell.h"

@implementation ShopCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imgView = [[UIImageView alloc]init];
        [self.contentView addSubview:self.imgView];
        self.bigMoneyLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.bigMoneyLabel];
        self.littleMoneyLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.littleMoneyLabel];
        self.nameLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.nameLabel];
        
        self.typeLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.typeLabel];
        
        self.buyNumBtn = [[UIButton alloc]init];
        [self.contentView addSubview:self.buyNumBtn];
        
        self.changeNumView = [[UIView alloc]init];
        [self.contentView addSubview:self.changeNumView];
        
        self.subBtn = [[UIButton alloc]init];
        [self.changeNumView addSubview:self.subBtn];
        
        self.addBtn = [[UIButton alloc]init];
        [self.changeNumView addSubview:self.addBtn];
        
        self.numLabel = [[UILabel alloc]init];
        [self.changeNumView addSubview:self.numLabel];
        
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    NSLog(@"%@",NSStringFromCGSize(layoutAttributes.bounds.size));
    // 图片
    
    self.bigMoneyLabel.textColor = [UIColor redColor];
    if (iphone4 || iphone5) {
        self.bigMoneyLabel.font = [UIFont systemFontOfSize:14];
    }else{
        self.bigMoneyLabel.font = [UIFont systemFontOfSize:16];
        [self.bigMoneyLabel sizeToFit];
    }

    
    self.nameLabel.textColor = [UIColor getColorFromRGBString:@"909090"];
    self.nameLabel.font = [UIFont systemFontOfSize:12];
    
    
    self.typeLabel.textColor = [UIColor getColorFromRGBString:@"909090"];
    
    if (iphone4 || iphone5) {
        self.typeLabel.font = [UIFont systemFontOfSize:9];
    }else{
        self.typeLabel.font = [UIFont systemFontOfSize:11];
    }
    
    
    self.littleMoneyLabel.font = [UIFont systemFontOfSize:11];
    self.littleMoneyLabel.textColor = [UIColor getColorFromRGBString:@"909090"];
    
    [self.buyNumBtn setImage:[UIImage imageNamed:@"sysicon_n_09@1x"] forState:UIControlStateNormal];
    [self.buyNumBtn addTarget:self action:@selector(buyNumBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 购买数量View
    self.changeNumView.backgroundColor = [UIColor orangeColor];
    self.changeNumView.hidden = YES;
    self.addBtn.backgroundColor = [UIColor blueColor];
    [self.addBtn addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    self.subBtn.backgroundColor = [UIColor blueColor];
    [self.subBtn addTarget:self action:@selector(subBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.subBtn.mas_right);
        make.right.equalTo(self.addBtn.mas_left);
        make.height.mas_equalTo(20);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imgView.mas_bottom).offset(24);
        make.left.equalTo(self).offset(5);
    }];
    
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(7);
        make.left.equalTo(self).offset(5);
    }];
    
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.centerX.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(86, 86 - 14));
    }];
    
    [self.bigMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.typeLabel.mas_bottom).offset(7);
        make.left.equalTo(self).offset(5);
        make.size.mas_equalTo(CGSizeMake(layoutAttributes.bounds.size.width, 16));
    }];
    
    [self.littleMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(ZTY_SCREEN_WIDTH/3/2 - 10);
        make.bottom.equalTo(self.bigMoneyLabel);
        make.left.mas_equalTo(CGSizeMake(100, 11));
    }];
    
    if (iphone4 || iphone5) {
        [self.buyNumBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-5);
            make.centerY.equalTo(self.bigMoneyLabel);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
    }else{
        [self.buyNumBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-10);
            make.centerY.equalTo(self.bigMoneyLabel);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
    }
    
    
    [self.changeNumView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.typeLabel.mas_bottom).offset(5);
        make.left.equalTo(self).offset(5);
        make.right.equalTo(self).offset(-5);
        make.size.mas_equalTo(CGSizeMake(self.contentView.frame.size.width, 20));
    }];
    
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.equalTo(self.changeNumView);
        make.width.mas_equalTo(20);
    }];
    
    [self.subBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.equalTo(self.changeNumView);
        make.width.mas_equalTo(20);
    }];
    
    
    self.imgView.image = [UIImage imageNamed:@"user_pic_06"];
    self.bigMoneyLabel.text = @"¥25.0";
    self.typeLabel.text = @"规格:1kg";
    self.nameLabel.text = @"新疆吐鲁番葡萄干";
    self.littleMoneyLabel.text = @"¥30.0";
}


- (void)buyNumBtnAction:(UIButton *)sender{
    // 购买加号方法
    self.changeNumView.hidden = NO;
}

- (void)addBtnAction:(UIButton *)sender{
    // 添加数量
}

- (void)subBtnAction:(UIButton *)sender{
    // 减少数量
}




@end
